// 引入发请求的api
import { reqCategoryList, reqGetBanner, reqFloorList } from "@/api/index"

// Home模块的小仓库
const state = {
    // state中数据默认初始值别瞎写，服务器返回对象起始值是对象，服务器返回数组起始值是数组
    categoryList: [],
    bannerList: [],
    floorList: []
};
const mutations = {
    CATEGORYLIST(state, categoryList) {
        state.categoryList = categoryList;
    },
    BANNERLIST(state, bannerList) {
        state.bannerList = bannerList;
    },
    FLOORLIST(state, floorList) {
        state.floorList = floorList;
    }
};
const actions = {
    // 获取三级联动列表的数据
    async getCategoryList({ commit }) {
        // 通过API里面的接口函数调用，向服务器发请求，获取服务器的数据
        let res = await reqCategoryList();
        if (res.code === 200) {
            commit("CATEGORYLIST", res.data)
        }
    },
    // 获取轮播图的数据
    getBannerList({ commit }) {
        let res = reqGetBanner();
        res.then(
            res => {
                if (res.code == 200) {
                    commit("BANNERLIST", res.data)
                }
            }
        )
    },

    async getFloorList(context) {
        let res = await reqFloorList();
        if (res.code === 200)
            context.commit("FLOORLIST", res.data)

    }

};
const getters = {};
export default {
    state,
    mutations,
    actions,
    getters
}